package com.example.planetexploder.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.planetexploder.R;

import java.util.ArrayList;

public class MyAdapter_Picture extends BaseAdapter {
    private ArrayList<Bitmap> myList;
    private Context mContext;
    private ImageView grid_image;
    private View deleteView;
    private boolean isShowDelete;// 根据这个变量来判断是否显示删除图标，true是显示，false是不显示

    public MyAdapter_Picture(Context mContext,
                              ArrayList<Bitmap> myList) {
        this.mContext = mContext;
        this.myList = myList;
    }

    public void setIsShowDelete(boolean isShowDelete) {
        this.isShowDelete = isShowDelete;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {

        return myList.size();
    }

    @Override
    public Object getItem(int position) {
        return myList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.griditem_picture, null);
        grid_image = convertView.findViewById(R.id.grid_image_picture);
        deleteView = convertView.findViewById(R.id.delete_PictureView);
        deleteView.setVisibility(isShowDelete ? View.VISIBLE : View.GONE);// 设置删除按钮是否显示
        grid_image.setImageBitmap(myList.get(position));
        return convertView;
    }
}
